1 module std.vita.socket;
2 version(PSVita):
3 
4 
5 nothrow @nogc int socketpair(int a, int b, int c , ref int[2] d)
6 {
7 	return socketpair(a,b,c,d.ptr);
8 }
9 
10 
11 nothrow @nogc extern(C):
12 
13 /*	$NetBSD: socket.h,v 1.77 2005/11/29 03:12:16 christos Exp $	*/
14 
15 /*
16  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions
21  * are met:
22  * 1. Redistributions of source code must retain the above copyright
23  *    notice, this list of conditions and the following disclaimer.
24  * 2. Redistributions in binary form must reproduce the above copyright
25  *    notice, this list of conditions and the following disclaimer in the
26  *    documentation and/or other materials provided with the distribution.
27  * 3. Neither the name of the project nor the names of its contributors
28  *    may be used to endorse or promote products derived from this software
29  *    without specific prior written permission.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
32  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
35  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41  * SUCH DAMAGE.
42  */
43 
44 /*
45  * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
46  *	The Regents of the University of California.  All rights reserved.
47  *
48  * Redistribution and use in source and binary forms, with or without
49  * modification, are permitted provided that the following conditions
50  * are met:
51  * 1. Redistributions of source code must retain the above copyright
52  *    notice, this list of conditions and the following disclaimer.
53  * 2. Redistributions in binary form must reproduce the above copyright
54  *    notice, this list of conditions and the following disclaimer in the
55  *    documentation and/or other materials provided with the distribution.
56  * 3. Neither the name of the University nor the names of its contributors
57  *    may be used to endorse or promote products derived from this software
58  *    without specific prior written permission.
59  *
60  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
61  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
64  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70  * SUCH DAMAGE.
71  *
72  *	@(#)socket.h	8.6 (Berkeley) 5/3/95
73  */
74 
75 import core.stdc.stdint;
76 
77 alias sa_family_t = uint8_t ;
78 alias socklen_t = uint32_t ;
79 
80 enum	FD_SETSIZE = 	256;
81 
82 /*
83  * Socket types.
84  */
85 enum	SOCK_STREAM	= 1;		/* stream socket */
86 enum	SOCK_DGRAM	= 2;		/* datagram socket */
87 enum	SOCK_RAW	= 3;		/* raw-protocol interface */
88 enum	SOCK_RDM	= 4;		/* reliably-delivered message */
89 enum	SOCK_SEQPACKET	= 5;		/* sequenced packet stream */
90 
91 /*
92  * Option flags per-socket.
93  */
94 enum SO_DEBUG = 0x0001;		/* turn on debugging info recording */
95 enum SO_ACCEPTCONN = 0x0002;		/* socket has had listen() */
96 enum SO_REUSEADDR = 0x0004;		/* allow local address reuse */
97 enum SO_KEEPALIVE = 0x0008;		/* keep connections alive */
98 enum SO_DONTROUTE = 0x0010;		/* just use interface addresses */
99 enum SO_BROADCAST = 0x0020;		/* permit sending of broadcast msgs */
100 enum SO_USELOOPBACK = 0x0040;		/* bypass hardware when possible */
101 enum SO_LINGER = 0x0080;		/* linger on close if data present */
102 enum SO_OOBINLINE = 0x0100;		/* leave received OOB data in line */
103 enum SO_REUSEPORT = 0x0200;		/* allow local address & port reuse */
104 enum SO_TIMESTAMP = 0x0400;		/* timestamp received dgram traffic */
105 
106 /*
107  * Additional options, not kept in so_options.
108  */
109 enum SO_SNDBUF = 0x1001;		/* send buffer size */
110 enum SO_RCVBUF = 0x1002;		/* receive buffer size */
111 enum SO_SNDLOWAT = 0x1003;		/* send low-water mark */
112 enum SO_RCVLOWAT = 0x1004;		/* receive low-water mark */
113 enum SO_SNDTIMEO = 0x1005;		/* send timeout */
114 enum SO_RCVTIMEO = 0x1006;		/* receive timeout */
115 enum SO_ERROR = 0x1007;		/* get error status and clear */
116 enum SO_TYPE = 0x1008;		/* get socket type */
117 enum SO_OVERFLOWED = 0x1009;		/* datagrams: return packets dropped */
118 enum SO_NONBLOCK = 0x1100;		/* non-blocking I/O */
119 
120 /*
121  * Structure used for manipulating linger option.
122  */
123 struct	linger {
124 	int	l_onoff;		/* option on/off */
125 	int	l_linger;		/* linger time in seconds */
126 }
127 
128 /*
129  * Level number for (get/set)sockopt() to apply to socket itself.
130  */
131 enum	SOL_SOCKET =	0xffff;		/* options for socket level */
132 
133 /*
134  * Address families.
135  */
136 enum AF_UNSPEC = 0;		/* unspecified */
137 enum AF_LOCAL = 1;		/* local to host (pipes, portals) */
138 enum AF_UNIX = AF_LOCAL;	/* backward compatibility */
139 enum AF_INET = 2;		/* internetwork: UDP, TCP, etc. */
140 enum AF_IMPLINK = 3;		/* arpanet imp addresses */
141 enum AF_PUP = 4;		/* pup protocols: e.g. BSP */
142 enum AF_CHAOS = 5;		/* mit CHAOS protocols */
143 enum AF_NS = 6;		/* XEROX NS protocols */
144 enum AF_ISO = 7;		/* ISO protocols */
145 enum AF_OSI = AF_ISO;
146 enum AF_ECMA = 8;		/* european computer manufacturers */
147 enum AF_DATAKIT = 9;		/* datakit protocols */
148 enum AF_CCITT = 10;		/* CCITT protocols, X.25 etc */
149 enum AF_SNA = 11;		/* IBM SNA */
150 enum AF_DECnet = 12;		/* DECnet */
151 enum AF_DLI = 13;		/* DEC Direct data link interface */
152 enum AF_LAT = 14;		/* LAT */
153 enum AF_HYLINK = 15;		/* NSC Hyperchannel */
154 enum AF_APPLETALK = 16;		/* Apple Talk */
155 enum AF_ROUTE = 17;		/* Internal Routing Protocol */
156 enum AF_LINK = 18;		/* Link layer interface */
157 enum AF_COIP = 20;		/* connection-oriented IP, aka ST II */
158 enum AF_CNT = 21;		/* Computer Network Technology */
159 enum AF_IPX = 23;		/* Novell Internet Protocol */
160 enum AF_INET6 = 24;		/* IP version 6 */
161 enum AF_ISDN = 26;		/* Integrated Services Digital Network*/
162 enum AF_E164 = AF_ISDN;		/* CCITT E.164 recommendation */
163 enum AF_NATM = 27;		/* native ATM access */
164 enum AF_ARP = 28;		/* (rev.) addr. res. prot. (RFC 826) */
165 enum AF_MAX = 31;
166 
167 /*
168  * Structure used by kernel to store most
169  * addresses.
170  */
171 struct sockaddr {
172 	uint8_t	sa_len;		/* total length */
173 	sa_family_t	sa_family;	/* address family */
174 	char[14]		sa_data;	/* actually longer; address value */
175 }
176 
177 enum _SS_MAXSIZE = 128U;
178 enum _SS_ALIGNSIZE = int64_t.sizeof;
179 enum _SS_PAD1SIZE = (_SS_ALIGNSIZE - uint8_t.sizeof - sa_family_t.sizeof);
180 enum _SS_PAD2SIZE = (_SS_MAXSIZE - uint8_t.sizeof - sa_family_t.sizeof - _SS_PAD1SIZE - _SS_ALIGNSIZE);
181 
182 struct sockaddr_storage {
183 	uint8_t		ss_len;
184 	sa_family_t	ss_family;
185 	char[_SS_PAD1SIZE] 		__ss_pad1;
186 	int64_t		__ss_align;
187 	char[_SS_PAD2SIZE]		__ss_pad2;
188 }
189 
190 /*
191  * Protocol families, same as address families for now.
192  */
193 enum PF_UNSPEC = AF_UNSPEC;
194 enum PF_LOCAL = AF_LOCAL;
195 enum PF_UNIX = PF_LOCAL;	/* backward compatibility */
196 enum PF_INET = AF_INET;
197 enum PF_IMPLINK = AF_IMPLINK;
198 enum PF_PUP = AF_PUP;
199 enum PF_CHAOS = AF_CHAOS;
200 enum PF_NS = AF_NS;
201 enum PF_ISO = AF_ISO;
202 enum PF_OSI = AF_ISO;
203 enum PF_ECMA = AF_ECMA;
204 enum PF_DATAKIT = AF_DATAKIT;
205 enum PF_CCITT = AF_CCITT;
206 enum PF_SNA = AF_SNA;
207 enum PF_DECnet = AF_DECnet;
208 enum PF_DLI = AF_DLI;
209 enum PF_LAT = AF_LAT;
210 enum PF_HYLINK = AF_HYLINK;
211 enum PF_APPLETALK = AF_APPLETALK;
212 enum PF_ROUTE = AF_ROUTE;
213 enum PF_LINK = AF_LINK;
214 
215 enum PF_COIP = AF_COIP;
216 enum PF_CNT = AF_CNT;
217 enum PF_INET6 = AF_INET6;
218 enum PF_IPX = AF_IPX;		/* same format as AF_NS */
219 enum PF_ISDN = AF_ISDN;		/* same as E164 */
220 enum PF_E164 = AF_E164;
221 enum PF_NATM = AF_NATM;
222 enum PF_ARP = AF_ARP;
223 enum PF_MAX = AF_MAX;
224 enum MSG_OOB = 0x1;		/* process out-of-band data */
225 enum MSG_PEEK = 0x2;		/* peek at incoming message */
226 enum MSG_DONTROUTE = 0x4;		/* send without using routing tables */
227 enum MSG_EOR = 0x8;		/* data completes record */
228 enum MSG_TRUNC = 0x10;		/* data discarded before delivery */
229 enum MSG_CTRUNC = 0x20;		/* control data lost before delivery */
230 enum MSG_WAITALL = 0x40;		/* wait for full request or error */
231 enum MSG_DONTWAIT = 0x80;		/* this message should be nonblocking */
232 enum MSG_BCAST = 0x100;		/* this message was rcvd using link-level brdcst */
233 enum MSG_MCAST = 0x200;		/* this message was rcvd using link-level mcast */
234 
235 /*
236  * Types of socket shutdown(2).
237  */
238 enum SHUT_RD = 0;		/* Disallow further receives. */
239 enum SHUT_WR = 1;		/* Disallow further sends. */
240 enum SHUT_RDWR = 2;		/* Disallow further sends/receives. */
241 
242 struct iovec {
243 	void	*iov_base;	/* Base address. */
244 	size_t	 iov_len;	/* Length. */
245 }
246 
247 struct msghdr {
248 	void		*msg_name;	/* optional address */
249 	socklen_t	msg_namelen;	/* size of address */
250 	iovec	*msg_iov;	/* scatter/gather array */
251 	int		msg_iovlen;	/* # elements in msg_iov */
252 	void		*msg_control;	/* ancillary data, see below */
253 	socklen_t	msg_controllen;	/* ancillary data buffer len */
254 	int		msg_flags;	/* flags on received message */
255 }
256 
257 /* BSD-compatible socket API. */
258 int	accept(int, sockaddr * __restrict, socklen_t * __restrict);
259 int	bind(int, const sockaddr *, socklen_t);
260 int	connect(int, const sockaddr *, socklen_t);
261 int	getpeername(int, sockaddr * __restrict, socklen_t * __restrict);
262 int	getsockname(int, sockaddr * __restrict, socklen_t * __restrict);
263 
264 int getnameinfo(sockaddr* addr,size_t addrlen, char* host, size_t hostlen,
265     char* serv,size_t servlen, int flags);
266 
267 int	getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
268 int	listen(int, int);
269 ssize_t	recv(int, void *, size_t, int);
270 ssize_t	recvfrom(int, void * __restrict, size_t, int,
271 		sockaddr * __restrict, socklen_t * __restrict);
272 ssize_t recvmsg(int s, msghdr *msg, int flags);
273 ssize_t	send(int, const void *, size_t, int);
274 ssize_t	sendto(int, const void *,
275 		size_t, int, const sockaddr *, socklen_t);
276 ssize_t sendmsg(int s, const msghdr *msg, int flags);
277 int	setsockopt(int, int, int, const void *, socklen_t);
278 int	shutdown(int, int);
279 int	socket(int, int, int);
280 int	socketpair(int, int, int, int *);